package com.eptok.gw.szcups.service;

import ys8583.parse.IOMessage;

import com.eptok.gw.szcups.cups.CupsMessageControl;
import com.eptok.gw.szcups.cups.message.PackMessageUtil;
import com.eptok.gw.szcups.pojo.BkCardBncQry;
import com.eptok.gw.szcups.pojo.XmlMessage;
import com.eptok.gw.szcups.socket.client.factory.ClientFactory;
import com.eptok.gw.szcups.util.SerialNumber;

/**
 * 银行卡余额查询
 * @author guoq
 *
 */
public class CardQueryService extends BaseService {
	
	public CardQueryService(){
		
	}

	@Override
	public IOMessage process(XmlMessage xmlMessage) throws Exception {
		log.debug("CardQueryService process start");
		BkCardBncQry pay = (BkCardBncQry)xmlMessage;
		IOMessage iomessagereq = PackMessageUtil.packCardBlanceQry(pay);
		long id = this.insertlog(pay, iomessagereq);
		ClientFactory.getInstance().sendMessage(CupsMessageControl.CHAN_CLIENT_KEY, iomessagereq);
		IOMessage iomessagersp = CupsMessageControl.getInstance().getChanMessageRsp((String)iomessagereq.getRspField(11));
		if(iomessagersp == null){
			pay.setStatus("Z2");
			pay.setRspSerialNumber(SerialNumber.seqno());
		}else{
			pay.setStatus((String)iomessagersp.getReqMesField(39));
			pay.setRspSerialNumber(SerialNumber.seqno());
			if(pay.getStatus().equals("00")){
				pay.setAccountAmt(((String)iomessagersp.getReqMesField(54)).substring(11, 11+12));  //获得银行卡余额
			}
		}
		this.updatelog(id, pay, iomessagersp);
		log.debug("CardQueryService process end");
		return iomessagersp;	
	}

	
}
